def ep(n):
    if n<=1: return False
    if n<=3: return True
    if n%2==0 or n%3==0: return False
    i=5
    while i*i<=n:
        if n%i==0 or n%(i+2)==0: return False
        i+=6
    return True
def bp(n):
    if n<100 or n>999: return "Wrong input"
    l=n; u=n
    while True:
        if ep(l): return l
        elif ep(u): return u
        else: l-=1; u+=1
w={"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
r=str(input())
if sum(c.isdigit() for v in r)==0: 
    n="".join(map(w.get, r.split()))
    print(bp(int(n)))
else: print("Wrong input")